package com.hq.vieorecyclerview.video.fragment;
import android.os.Bundle;
import android.util.Log;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.hq.vieorecyclerview.R;
import com.hq.vieorecyclerview.video.Adapter.VideoMessageAdapter;
import com.hq.vieorecyclerview.video.Adapter.VideoModel;


/**
 * 首页页面 Fragment
 */
public class HomeFragment extends Fragment {
    private VideoModel model=null;
    private VideoMessageAdapter adapter;
    private RecyclerView rv;

    @Override
    public void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //初始化视频数据保存 实力
        this.model= new ViewModelProvider(requireActivity()).get(VideoModel.class);
        //适配器实力
        this.adapter = new VideoMessageAdapter(model);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_home, container, false);
        //首页视频展示
        this.rv = view.findViewById(R.id.video_recycer);
        // 添加布局风格
        this.rv.setLayoutManager(new GridLayoutManager(view.getContext(), 2));
        this.rv.setAdapter(adapter);
        return view;
    }

    @Override
    public void onStart() {
        super.onStart();
        adapter.notifyDataSetChanged();
        Log.d("onBindViewHolder","数量= HomeFragment");
    }
}
